package com.atstudy.exception;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/22 10:43
 * @copyright: 博为峰
 */
public class ExceptionDemo03 {
    public static void main(String[] args) {
        int[] arr = new int[3];
        arr = null;
        try {
            m1(arr, 10);
        } catch (NullPointerException e) {
            e.printStackTrace();
            System.out.println("空指针已处理");
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("下标越界已处理");
        } catch (Exception e) {
            System.out.println("已处理");
        } finally {
//            System.exit(1);//退出虚拟机
            System.out.println("一定会执行");
        }
        System.out.println("后续代码");
    }

    public static void m1(int[] arr, int index) {
        if (arr == null) {
            throw new NullPointerException("空指针");
        }
        if (index >= arr.length) {
            throw new ArrayIndexOutOfBoundsException("下标越界");
        }
        System.out.println(arr[index]);
    }
}
